package high;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 47868
 */
public class ThreadPrint1 {
    public static AtomicInteger atomicInteger = new AtomicInteger(0);
    public static volatile Boolean isTrue = true;
    public static void main(String[] args) {
        new Thread(()->{
            while(atomicInteger.get()<=200){
                if(isTrue){
                    System.out.println(Thread.currentThread().getName() + "打印出" + atomicInteger.getAndIncrement());
                    isTrue = !isTrue;
                }

            }
        }).start();
        new Thread(()->{
            while(atomicInteger.get()<=200){
                if(!isTrue){
                    System.out.println(Thread.currentThread().getName() + "打印出" + atomicInteger.getAndIncrement());
                    isTrue = !isTrue;
                }

            }
        }).start();
    }
}
